<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>认识 WebGL</title>
</head>
<body>
    
    <div class="canvas-wrap">
        <canvas id="myCanvas" width="500" height="500"></canvas>
    </div>

    <script>
        function init () {
            const canvas = document.querySelector('#myCanvas');
            const webgl = canvas.getContext('webgl');

            // 设置 webgl 视口, 与 canvas 大小一致
            webgl.viewport(0, 0, canvas.clientWidth, canvas.clientHeight);

            // 设置颜色缓冲区为黑色
            webgl.clearColor(0.0, 0.0, 0.0, 1.0);
            // 清空背景
            webgl.clear(webgl.COLOR_BUFFER_BIT);
        }

        init();
    </script>
</body>
</html>